package com.hxkcloud.patient.aerotel.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;


import com.hxkcloud.patient.R;
import com.hxkcloud.patient.aerotel.domain.health.HealthDevice;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by daipengfei on 16/3/26.
 */
public class DeviceListAdapter extends BaseAdapter {

    private LayoutInflater mInflater;

    private List<HealthDevice> devices = new ArrayList<>();

    public DeviceListAdapter(Context context, List<HealthDevice> devices) {
        mInflater = LayoutInflater.from(context);
        this.devices = devices;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public Object getItem(int position) {
        if (position < devices.size()) {
            return devices.get(position);
        } else
            return null;
    }

    public static class ViewHolder {
        public TextView name;
        public TextView mac;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        HealthDevice device = devices.get(position);
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.paired_devices_list, null);
            TextView tvname = (TextView) convertView.findViewById(R.id.btname);
            TextView tvmac = (TextView) convertView.findViewById(R.id.btmac);

            ViewHolder vh = new ViewHolder();
            vh.name = tvname;
            vh.mac = tvmac;

            convertView.setTag(vh);

            tvname.setText(device.getName());
            tvmac.setText("蓝牙MAC地址".concat(device.getBtmac()));
        } else {
            ViewHolder vh = (ViewHolder) convertView.getTag();
            vh.name.setText(device.getName());
            vh.mac.setText("蓝牙MAC地址".concat(device.getBtmac()));
        }
        return convertView;
    }
    @Override
    public int getCount() {
        return devices.size();
    }
}
